<%@ page language="java" pageEncoding="UTF-8"
	errorPage="../../defaultException.jsp"%>
<%@include file="../../tags.jsp"%>
<html>
<head>
<title>新闻信息管理</title>
<%@include file="../../head.jsp"%>

</head>
<body>

	<table class="fitem">
		<tr>
			<td><label>目的地名称:</label></td>
			<td><input id="destId" type="text" /></td>
			<td align="right"><button id="sub" value="查询"
					onclick="searchForm()">查询</button>
			</td>
		</tr>
	</table>
	
	<table id="list_data" cellspacing="0" cellpadding="0">
		<thead>
			<tr>
				<th field="name">行程地点名称</th>
				<th field="summary">地点摘要</th>
				<th field="lat">纬度</th>
				<th field="lng">经度</th>
				<th field="stayTime">停留时间</th>
				<th field="categoryName">类别名称</th>
				<th field="destName">归属目的地名称</th>
				<th field="status" formatter="tripdestStatus">系统状态</th>
				<th field="custom" formatter="tripdestCustom">定义类型</th>
				<th field="image" formatter="formatCell">图片</th>
			</tr>
		</thead>
	</table>
	<script type="text/javascript">
		function formatCell(value, row, index) {
			return "<img src='${image_domain}" + value
					+ "@!small' width='150' height='100'>";
		}

		var custom = {
			'1' : '自定义',
			'0' : '系统定义'
		};
		function tripdestCustom(value, row, index) {
			return custom[value];
		}
		var status = {
			'1' : '已审核',
			'0' : '未审核'
		};
		function tripdestStatus(value, row, index) {
			return status[value];
		}
	</script>

	<div id="tripdestDialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true">
	</div>

	<script type="text/javascript">
		var toolb;
		if ('${tripdest.destId}' != 0) {
			toolb = [
					{

						text : '同步目的地地点',
						iconCls : 'icon-add',
						handler : function() {
							var synAction = cpath
									+ '/admin/trip/synlocation?tripdestId=${tripdest.tripdestId}&destId=${tripdest.destId}&name=${tripdest.name}';
							if ('${tripdest.destId}' != 0) {
								synDestLocationInfo(synAction);
							} else {
								alert("自定义目的地不需要做同步操作！");
							}
						}
					},
					'-',
					{
						text : '同步目的地交通',
						iconCls : 'icon-add',
						handler : function() {
							var synAction = cpath
									+ '/admin/trip/syntraffic?tripdestId=${tripdest.tripdestId}&destId=${tripdest.destId}&name=${tripdest.name}';
							synDestLocationInfo(synAction);
						}
					},
					'-',
					{
						text : '修改地点信息',
						iconCls : 'icon-edit',
						handler : function() {
							var saveAction = cpath
									+ '/admin/trip/triplocation/update';
							var openAction = cpath
									+ '/admin/trip/triplocation/vupdate';
							openUpdateNewsDialog('修改地点信息', openAction,
									saveAction, tripdestSuccess,
									getSelectTripdest);
						}
					}, '-', {
						text : '刷新',
						iconCls : 'icon-reload',
						handler : function() {
							$('#list_data').datagrid('reload');
							save_status = false;
						}
					} ];
		} else {
			toolb = [
					{
						text : '修改行程目的地信息',
						iconCls : 'icon-edit',
						handler : function() {
							var saveAction = cpath
									+ '/admin/trip/triplocation/update';
							var openAction = cpath
									+ '/admin/trip/triplocation/vupdate';
							openUpdateNewsDialog('修改行程目的地信息', openAction,
									saveAction, tripdestSuccess,
									getSelectTripdest);
						}
					}, '-', {
						text : '刷新',
						iconCls : 'icon-reload',
						handler : function() {
							$('#list_data').datagrid('reload');
							save_status = false;
						}
					} ];
		}
		$('#list_data')
				.datagrid(
						{
							title : '<a href=${cpath}/admin/trip/tripdest/vlist >行程目的地</a>&gt;&gt;${tripdest.name}地点信息',
							iconCls : 'icon-edit',//图标 
							width : 1024,
							height : 500,
							doSize : true,
							nowrap : false,
							striped : true,
							border : true,
							collapsible : false,//是否可折叠的 
							fitColumns : true,//自动大小 
							fit : false,
							url : '${cpath }/admin/trip/triplocation/list?tripdestId=${tripdest.tripdestId}',
							remoteSort : false,
							idField : 'locationId',
							singleSelect : true,//是否单选 
							pagination : true,//分页控件 
							rownumbers : true,//行号 
							toolbar : toolb
						});
		//设置分页控件 
		var p = $('#list_data').datagrid('getPager');
		$(p).pagination({
			pageSize : 10,//每页显示的记录条数，默认为10 
			pageList : [ 5, 10, 15 ],//可以设置每页记录条数的列表 
			beforePageText : '第',//页数文本框前显示的汉字 
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录'
		/*onBeforeRefresh:function(){
		    $(this).pagination('loading');
		    alert('before refresh');
		    $(this).pagination('loaded');
		}*/
		});
	</script>
	<script type="text/javascript">
		var url;
		var cpath = '${cpath}';

		function getSelectTripdest() {
			return $('#list_data').datagrid('getSelected');
		}

		function tripdestSuccess() {
			$('#list_data').datagrid('reload'); // reload the user data
		}

		function synDestLocationInfo(synAction) {
			$.post(synAction, null, function(result) {
				if (result.resultCode === '00000000') {
					$('#list_data').datagrid('reload'); // reload the user data
					$.messager.alert("提示", result.resultMsg, "info");
				} else {
					$.messager.alert("错误", result.resultMsg, "error");
				}
			}, 'json');
		}
		function openUpdateNewsDialog(dlgtitle, openAction, saveAction,
				successCallback, getSelectTripdest) {

			//添加信息，需要是否有前置条件
			if (getSelectTripdest) {
				var row = getSelectTripdest();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择要修改 的行程目的地！", "info");
					return;
				} else {
					//选中了一行需在saveAction后加上目的地编号
					openAction += '?locationId=' + row.locationId;
					$('#tripdestDialog').dialog({
						title : dlgtitle,
						width : 800,
						height : 550,
						closed : false,
						cache : false,
						resizable : true,
						href : openAction,
						modal : true,
						closed : true,
						buttons : [ {
							text : '保存',
							iconCls : "icon-ok",
							handler : function() {
								saveForm(saveAction, successCallback);
							}
						}, {
							text : '取消',
							iconCls : "icon-cancel",
							handler : function() {
								$('#tripdestDialog').dialog('close');
							}
						} ]
					});
					$('#tripdestDialog').dialog('open');
					$('#list_data').datagrid('clearSelections');
				}
			}
		}
		var save_status = false;
		function saveForm(saveAction, successCallback) {
			if (save_status) {
				$.messager.alert("提示", "请耐心等待。。。后台执行中。。。", "info");
				return;
			}
			save_status = true;
			$('#fm').form('submit', {
				url : saveAction,
				onSubmit : function() {
					var result = $(this).form('validate');
					if (!result) {
						save_status = false;
					}
					return result;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.resultCode !== '00000000') {
						$.messager.alert("错误", result.resultMsg, "error");
						$('#list_data').datagrid('clearSelections');
					} else {
						$.messager.alert("成功", result.resultMsg, "info");
						$('#tripdestDialog').dialog('close');
						if (successCallback) {
							successCallback();
						}
						$('#list_data').datagrid('clearSelections');
					}
					save_status = false;
				}
			});
		}
		function searchForm() {
			var destName = $('#destId').attr("value");

			$('#list_data').datagrid('load', {
				destName : destName
			});
		}

		function deleteTripdest(deleteAction, getSelectTripdest) {
			//添加信息，需要是否有前置条件
			if (getSelectTripdest) {

				var row = getSelectTripdest();
				//没有选中行，则需要提示
				if (!row) {
					$.messager.alert("提示", "请选择要删除的新闻！", "info");
					return;
				}
				if (row) {
					$.messager.confirm("提示", "确认要删除这条新闻吗？", function(r) {
						if (r) {
							$.post(deleteAction, row,
									function(result) {
										if (result.resultCode === '00000000') {
											$('#list_data').datagrid('reload'); // reload the user data
											$.messager.alert("提示",
													result.resultMsg, "info");
											$('#list_data').datagrid(
													'clearSelections');
										} else {
											$.messager.alert("错误",
													result.resultMsg, "error");
											$('#list_data').datagrid(
													'clearSelections');
										}
									}, 'json');
						}
					});
				}
			}
		}
		function searchForm() {
			var locationName = $('#destId').attr("value");

			$('#list_data').datagrid('load', {
				locationName : locationName
			});
		}
	</script>
	<style type="text/css">
#fm {
	margin: 0;
	padding: 40px 40px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 90px;
}
</style>
</body>
</html>